import {
	reqGetSearchInfo
} from '../../api'
// actions: 处理异步，书写业务逻辑
const actions = {
	//这里可以书写业务逻辑，但是不要修改state数据
	async getSearchList({commit}, params={}) {
		//reqGetSearchInfo 需要传递一个空对象
		let result = await reqGetSearchInfo(params)
		// console.log(result)
		if (result.code == 200) {
			commit("GETSEARCHLIST", result.data)
		}
	}
};

// mutations:修改state
const mutations = {
	GETSEARCHLIST(state, searchList) {
		state.searchList = searchList
		// console.log(state.searchList)
	}
};

//state:存储数据的地方
const state = {
	searchList:{}
};

// getters：相当于计算属性,可以简化数据
const getters = {
	goodsList(state){
		//为了防止网络延迟，没有请求到数据。
		return state.searchList.goodsList || []
		// console.log(state)
	},
	trademarkList(state){
		return state.searchList.trademarkList || []
		// console.log(state)
	},
	attrsList(state){
		return state.searchList.trademarkList || []
	}
};

//对外暴露Store实例
export default {
	state,
	mutations,
	actions,
	getters
}
